package com.codi.bus.core.dao.impl;

import com.codi.base.dao.BaseDAOImpl;
import com.codi.base.dao.plugin.page.PageView;
import com.codi.bus.core.dao.FundCombinationHistoryDao;
import com.codi.bus.core.domain.FundCombinationHistory;
import org.springframework.data.domain.Page;
//import org.springframework.data.assets.PageImpl;
import com.codi.base.dao.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("fundCombinationHistoryDao")
public class FundCombinationHistoryDaoImpl extends BaseDAOImpl<FundCombinationHistory> implements FundCombinationHistoryDao{

    @Override
    public int add(FundCombinationHistory fundCombinationHistory) {
        return this.insert(generateStatement("insert"), fundCombinationHistory);
    }

    @Override
    public List<FundCombinationHistory> queryByDate(Date date, String combinationCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("combinationCode", combinationCode);
        map.put("calDate", date);

        return this.findList(generateStatement("queryByDate"), map);
    }

    @Override
    public List<FundCombinationHistory> queryByTradeDate(String combinationCode, Date tradeDate) {
        Map<String, Object> map = new HashMap<>();
        map.put("combinationCode", combinationCode);
        map.put("tradeDate", tradeDate);

        return this.findList(generateStatement("queryByTradeDate"), map);
    }

    @Override
    public Page<FundCombinationHistory> queryByPage(Pageable pageable) {
        PageView pageView = getPageView(pageable.getPageNumber(), pageable.getPageSize());

        Map<String, Object> map = new HashMap<>();
        map.put("pageView", pageView);

        List<FundCombinationHistory> fundCombinationHistories = this.findList(generateStatement("queryByPage"), map);

        return new PageImpl<FundCombinationHistory>(fundCombinationHistories, pageable, pageView.getRowCount());
    }

    @Override
    public Page<FundCombinationHistory> queryByPageAndCombinationCode(Pageable pageable, String combinationCode) {
        PageView pageView = getPageView(pageable.getPageNumber(), pageable.getPageSize());

        Map<String, Object> map = new HashMap<>();
        map.put("pageView", pageView);
        map.put("combinationCode", combinationCode);

        List<FundCombinationHistory> fundCombinationHistories = this.findList(generateStatement("queryByPageAndCombinationCode"), map);

        return new PageImpl<FundCombinationHistory>(fundCombinationHistories, pageable, pageView.getRowCount());
    }

    @Override
    public int deleteByKey(Long combinationId) {
        return this.delete(generateStatement("deleteByPrimaryKey"), combinationId);
    }

    @Override
    public FundCombinationHistory queryById(Long combinationId) {
        return this.getObject(generateStatement("selectByPrimaryKey"), combinationId);
    }

    @Override
    public int updateById(FundCombinationHistory history) {
        return this.update(generateStatement("updateByPrimaryKeySelective"), history);
    }

    @Override
    public int addFundHistory(FundCombinationHistory fundCombinationHistory) {
        return this.insert(generateStatement("insertSelective"), fundCombinationHistory);
    }
}
